//
//  ViewController.m
//  Student
//
//  Created by kwsdzjx on 15/10/8.
//  Copyright © 2015年 周佳兴. All rights reserved.
//

#import "LoginViewController.h"
#import "Masonry.h"
#import "CustomTabbarViewController.h"
#import "ProjectModel.h"
#import "JPUSHService.h"
#import "UrlSettingViewController.h"
#import "ZMView.h"
#import "BQActivityView.h"
#import "JQIndicatorView.h"
#import <PgySDK/PgyManager.h>
#import <PgyUpdate/PgyUpdateManager.h>
#define IMGTEXTGEI @(18)

@interface LoginViewController ()<UITextFieldDelegate>{
    UITextField     *userNameText;
    UITextField     *passWordText;
    UIScrollView    *scroView;
    CGFloat          delta;
    UITextField     *focusTextField;
    NSString        *proID;
    UIActionSheet *actionsheet;
    UIButton *exchangeBtn;
    
    UIButton *btnPo;
    UIScrollView *_sv;
}
@property(nonatomic,strong)NSTimer *myTimer;
@property(nonatomic, strong)JQIndicatorView *indicator;
@end
static NSTimer *_sharedNSTimer = nil;
@implementation LoginViewController
- (void) keyboardWillShow:(NSNotification *)notify {
    NSLog(@"%@",NSStringFromCGRect(focusTextField.superview.superview.superview.frame));
    UIView *sv = focusTextField.superview.superview.superview;
    UIView *sv1 = focusTextField.superview.superview;
    CGFloat sv1Height = sv1.frame.origin.y+sv1.frame.size.height;
    UIView *sv2 = focusTextField.superview;
    CGFloat sv2Height = sv2.frame.origin.y ;
    
    CGFloat kbHeight = 256;//getKeyboardHeight(notify);
    CGFloat NewSumHeight = sv1Height+sv2Height+kbHeight;
    NSLog(@"%zd",NewSumHeight);
    // 取得键盘的动画时间
    double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    CGFloat screenHeight = self.view.bounds.size.height;
    //    [UIScreen mainScreen].bounds.size.height;
    
    CGFloat viewBottom = sv.frame.origin.y +NewSumHeight;
    if (viewBottom  < screenHeight) return;
    
    // 键盘会盖住输入框, 要移动整个view了
    delta = viewBottom - screenHeight-100/2+50;
    
    // masonry的地方了 mas_updateConstraints 更新superView的约束
    [scroView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(-delta);//.offset(50);
    }];
    [UIView animateWithDuration:duration animations:^void(void){
        // superView来重新布局
        [scroView layoutIfNeeded];
    }];
}
- (UIView *)createUserView:(NSString *)placeHolder andImageName:(NSString *)imageName andTag:(NSString *)tag andTitle:(NSString*)titleStr{
    UIView *baseView = [[UIView alloc]init];
    baseView.backgroundColor = [UIColor whiteColor];
    
    UIImageView *imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:imageName]];
    [baseView addSubview:imgView];
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(baseView.mas_left).offset(30/2);
        make.centerY.equalTo(baseView.mas_centerY);
        make.width.equalTo(@(25));
    }];
    UILabel *la = [[UILabel alloc]init];
    [baseView addSubview:la];
    
    
    UITextField *textField = [[UITextField alloc]init];
    textField.delegate = self;
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [baseView addSubview:textField];
    
    [la mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imgView.mas_right);
        make.centerY.equalTo(baseView.mas_centerY);
        make.width.equalTo(@(0));//title文字的宽度
        make.height.equalTo(IMGTEXTGEI);
    }];
    [la sizeToFit];
    //    la.backgroundColor = [UIColor redColor];
    
    la.textColor = [UIColor colorWithRed:0x5b/255.0 green:0x5b/255.0 blue:0x5b/255.0 alpha:1];
    la.font = [UIFont systemFontOfSize:32/2];
    
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(la.mas_right).offset(44/2);
        make.centerY.equalTo(la.mas_centerY);
        make.right.equalTo(baseView.mas_right);
        make.height.equalTo(@(100));
    }];
    
    //    [la mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.equalTo(baseView.mas_left);
    //        make.bottom.equalTo(baseView.mas_bottom).offset(-1);
    //        make.width.equalTo(@(35/2));
    //        make.height.equalTo(@(39/2));
    //    }];
    
    UIImageView *imgLine = [[UIImageView alloc]init];
    [baseView addSubview:imgLine];
    [imgLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(baseView.mas_left);
        make.right.equalTo(baseView.mas_right);
        make.bottom.equalTo(baseView.mas_bottom);
        make.height.equalTo(@(1));
    }];
    imgLine.hidden = YES;
    imgLine.backgroundColor = [UIColor colorWithHex:0xd1d1d1];
    
    la.text = titleStr;
    la.font = [UIFont systemFontOfSize:17];
    //    imgView.image = [UIImage imageNamed:@"account-拷贝"];
    textField.placeholder = placeHolder;
    if ([tag isEqualToString:@"user"]) {
        userNameText = textField;
    }else if ([tag isEqualToString:@"pass"]) {
        passWordText = textField;
        passWordText.secureTextEntry = YES;
    }
    
    return baseView;
    
    
    
}

#if Student
#pragma mark - create block with textField and ingView

#endif
- (void) keyboardWillHidden:(NSNotification *)notify {
    // 键盘动画时间
    double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    
    //    [superView mas_updateConstraints:^(MASConstraintMaker *make) {
    //        make.top.equalTo(@(0));
    //    }];
    [scroView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top);
    }];
    [UIView animateWithDuration:duration animations:^{
        
        [scroView layoutIfNeeded];
    }];
    delta = 0.0f;
}

-(void)scrollTimer{
    //    LoginViewController *fv = [[LoginViewController alloc]init];
    if (!_myTimer) {
        _myTimer = [LoginViewController sharedNSTimer];
    }
    [_myTimer invalidate];
    _myTimer = nil;
    [[NSNotificationCenter defaultCenter]postNotificationName:@"relogin" object:@"relogin"];
}

-(void)creatImages{
    
    for(int i =0;i<3;i++){
        UIImageView *img =[[UIImageView alloc]initWithFrame:CGRectMake(i*KWIDTH, 0, KWIDTH, KHEIGHT)];
        [_sv addSubview:img];
        //这里添加了角色判断   //引导页不需要修改
        NSString *str;
        if ([getUserType() isEqualToString:UserISHPSTeacher]) {
            str = [NSString stringWithFormat:@"引导页%d",i+1];
        }else if([getUserType() isEqualToString:UserISHPSStudent]){
            str = [NSString stringWithFormat:@"学生%d",i+1];
        }
        
        
        img.image =[UIImage imageNamed:str];
        
        if(i==2){
            
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(welcomeClick:)];
            [img addGestureRecognizer:tap];
            img.userInteractionEnabled = YES;
        }
    }
    
}

-(void)welcomeClick:(UITapGestureRecognizer *)tap{
    _sv.hidden = YES;
    scroView.hidden = NO;
    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    [ud setObject:@"NO" forKey:@"NEEDSV"];
    [ud synchronize];
    NSString *udStr = [ud objectForKey:@"NEEDSV"];
    NSLog(@"udstr: = %@",udStr);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    
    [[PgyUpdateManager sharedPgyManager] startManagerWithAppId:@"PGY_APP_ID"];   // 请将 PGY_APP_ID 换成应用的 App ID
    [[PgyUpdateManager sharedPgyManager] checkUpdate];
    
    //*** take out object ID
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    proID = [userDefault valueForKey:PROID];
    if (!proID) {
        [self getProId];
    }
    self.view.backgroundColor = [UIColor whiteColor];
    
    NSNotificationCenter *noti = [NSNotificationCenter defaultCenter];
    [noti addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    NSNotificationCenter *noti1 = [NSNotificationCenter defaultCenter];
    [noti1 addObserver:self selector:@selector(keyboardWillHidden:) name:UIKeyboardWillHideNotification object:nil];
    
    NSString *isLogin = [[NSUserDefaults standardUserDefaults]objectForKey:@"user"];
    NSString *pass = [[NSUserDefaults standardUserDefaults]objectForKey:@"pass"];
    if(isLogin==nil){
        [[NSUserDefaults standardUserDefaults]setObject:@"first" forKey:@"ifsave"];
    }
    else{
        [[NSUserDefaults standardUserDefaults]setObject:@"two" forKey:@"ifsave"];
    }
    //    UIView *baseView = [[UIView alloc] init];
    
    /*begain*/
    
    /*end*/
    
    //*** create UI
    
    if([getUIStyle() isEqualToString:STYLE0]){
        
        [self createUIStyle1AndString:@"" andString:@"" andString:@""];
        
    }else{
        [self createUIStyle1AndString:@"员" andString:@"学" andString:@"端"];
    }
    
    
    
    
    
    NSString *str = logState();
    if (isLogin&&pass&&![str isEqualToString:NLOGSTATE]){
        //[self loginBtnClick:_loginBtn];
        
    }
    
    
    //    btnPo = [[UIButton alloc]init];
    //    [self.view addSubview:btnPo];
    //    [btnPo mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.bottom.equalTo(self.view.mas_bottom).offset(-10);
    //        make.right.equalTo(self.view.mas_right).offset(-20);
    //        make.width.equalTo(@(40));
    //        make.height.equalTo(@(40));
    //    }];
    //
    //    [btnPo addTarget:self action:@selector(btnPoClick) forControlEvents:UIControlEventTouchUpInside];
    //
    //    [btnPo setTitle:@"切" forState:UIControlStateNormal];
    //    [btnPo setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    //    //*** default the userName text is editing
    //    //    [userNameText becomeFirstResponder];
}

#pragma mark - 切换 Url
-(void)btnPoClick{
    UrlSettingViewController *urlSettingVC = [[UrlSettingViewController alloc]init];
    [self presentViewController:urlSettingVC animated:YES completion:^{
        
    }];
}
#pragma mark - create the UI
//#ifdef Main

/*
 -(void)createUIStyle0{
 //***superView is all the base View
 scroView = [[UIScrollView alloc]init];
 [self.view addSubview:scroView];
 
 [scroView mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(self.view.mas_left);
 make.top.equalTo(self.view.mas_top);
 make.right.equalTo(self.view.mas_right);
 make.bottom.equalTo(self.view.mas_bottom);
 }];
 
 UIImageView *logoImg =[[UIImageView alloc]init];
 
 logoImg.image = [UIImage imageNamed:@"名称_"];
 
 [scroView addSubview:logoImg];
 
 
 scroView.backgroundColor = [UIColor clearColor];
 UIView *superView = scroView;
 //*** put the userName and passWord textFields
 UIView *baseView = [[UIView alloc]init];
 //    UILabel *titleLabel = [[UILabel alloc]init];
 //    [logoImg addSubview:titleLabel];
 //    titleLabel.text = @"客户化手机端";
 //    titleLabel.textAlignment = NSTextAlignmentCenter;
 //    titleLabel.textColor = [UIColor colorWithHex:0x00a4fd];
 //    titleLabel.font = [UIFont systemFontOfSize:30];
 
 [logoImg mas_makeConstraints:^(MASConstraintMaker *make) {
 make.centerX.equalTo(scroView.mas_centerX);
 make.top.equalTo(scroView.mas_top).offset(230/2);
 //        make.width.equalTo(self.view.mas_width);
 //        make.height.equalTo(@(66));
 }];
 
 //    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
 //        make.centerX.equalTo(logoImg.mas_centerX);
 //        make.centerY.equalTo(logoImg.mas_centerY);
 //        make.width.equalTo(self.view.mas_width);
 //        make.height.equalTo(@(66));
 //    }];
 
 //    logoImg.image = [UIImage imageNamed:@"图层-1"];
 
 //***create user block view
 
 
 
 UIView *userView = [self createViewWithPlaceHolder:@"请输入账号" andImageName:@"data-拷贝" andTag:@"user" andTitle:@"账号"];
 [baseView addSubview:userView];
 
 //***create passWord view
 UIView *passView = [self createViewWithPlaceHolder:@"请输入登录密码" andImageName:@"account-拷贝" andTag:@"pass" andTitle:@"密码"];
 [baseView addSubview:passView];
 
 //***userView layout
 [userView mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(baseView.mas_left);
 make.top.equalTo(baseView.mas_top);
 make.right.equalTo(baseView.mas_right);
 make.height.equalTo(@(90/2));
 }];
 
 //***passView layout
 [passView mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(userView.mas_left);
 make.top.equalTo(userView.mas_bottom).offset(1);
 make.right.equalTo(userView.mas_right);
 make.height.equalTo(userView.mas_height);
 }];
 
 
 [superView addSubview:baseView];
 
 
 //***baseView layout
 [baseView mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(superView.mas_left).offset(30/2);
 make.top.equalTo(logoImg.mas_bottom).offset(97/2);
 make.right.equalTo(self.view.mas_right).offset(-30/3);
 make.height.equalTo(@(280));
 }];
 
 //***loginButton
 _loginBtn = [[UIButton alloc]init];
 [baseView addSubview:_loginBtn];
 
 UIButton *cancelBtn = [[UIButton alloc]init];
 [baseView addSubview:cancelBtn];
 //    [loginBtn setTitle:@"登陆" forState:UIControlStateNormal];
 //    [_loginBtn setBackgroundImage:[UIImage imageNamed:@"index_into_normal"] forState:UIControlStateNormal];
 //    [_loginBtn setBackgroundImage:[UIImage imageNamed:@"index_into_press"] forState:UIControlStateHighlighted];
 [_loginBtn setBackgroundImage:[UIImage imageNamed:@"按钮_"] forState:UIControlStateNormal];
 [_loginBtn setImage:[UIImage imageNamed:@"登陆"] forState:UIControlStateHighlighted];
 [_loginBtn addTarget:self action:@selector(loginBtnClick:) forControlEvents:UIControlEventTouchUpInside];
 
 [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
 [_loginBtn setTitleColor:[UIColor colorWithHex:0xffffff] forState:UIControlStateNormal];
 
 //    [cancelBtn setImage:[UIImage imageNamed:@"取消"] forState:UIControlStateNormal];
 //    //    [loginBtn setImage:[UIImage imageNamed:@"登陆"] forState:UIControlStateHighlighted];
 //    [cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
 
 //***baseView layout
 [_loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(baseView.mas_left);
 make.height.equalTo(@(50));
 make.right.equalTo(baseView.mas_right);
 make.top.equalTo(passView.mas_bottom).offset(65/2);
 }];
 
 
 [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(baseView.mas_left);
 make.height.equalTo(@(50));
 make.right.equalTo(baseView.mas_right);
 make.top.equalTo(_loginBtn.mas_bottom).offset(26);
 }];
 //***superView add response gesture to resignFirstResponse
 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick)];
 [scroView addGestureRecognizer:tap];
 
 
 NSString *isLogin = [[NSUserDefaults standardUserDefaults]objectForKey:@"user"];
 NSString *pass = [[NSUserDefaults standardUserDefaults]objectForKey:@"pass"];
 if (isLogin)userNameText.text = isLogin;
 if(pass)passWordText.text = pass;
 
 
 exchangeBtn = [[UIButton alloc]init];
 [scroView addSubview:exchangeBtn];
 [exchangeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
 make.top.equalTo(scroView.mas_top).offset(40);
 make.right.equalTo(self.view.mas_right).offset(-10);
 make.width.equalTo(@(50));
 make.height.equalTo(@(30));
 }];
 
 [exchangeBtn setTitle:@"切换" forState:UIControlStateNormal];
 #pragma mark - 版本控制
 #ifdef Main
 NSLog(@"主项目程序");
 
 exchangeBtn.hidden = NO;
 #elif Student
 
 NSLog(@"学员端程序");
 //    [self dataRequest];
 
 //    return YES;
 exchangeBtn.hidden = YES;
 #elif Teacher
 //    rootview
 exchangeBtn.hidden = YES;
 NSLog(@"老师端程序");
 #else
 
 NSLog(@"都不是");
 #endif
 #pragma mark
 [exchangeBtn addTarget:self action:@selector(exchangeClick) forControlEvents:UIControlEventTouchUpInside];
 [exchangeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
 }*/
#pragma mark - 学员端代码



-(void)createUIStyle1AndString:(NSString *)secondS andString:(NSString *)firstS andString:(NSString *)lastS{
    //这里添加功能判断
    if (getMainLoginUI()) {
        scroView = [[UIScrollView alloc]init];
        [self.view addSubview:scroView];
        
        [scroView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left);
            make.top.equalTo(self.view.mas_top);
            make.right.equalTo(self.view.mas_right);
            make.bottom.equalTo(self.view.mas_bottom);
        }];
        
        UIImageView *logoImg =[[UIImageView alloc]init];
        //这里添加版本UI判断
        if ([getUIStyle() isEqualToString:STYLE0]) {
            logoImg.image = [UIImage imageNamed:@"index_logo_Main"];
        }else{
            logoImg.image = [UIImage imageNamed:@"index_logo"];
        }
        
        
        [scroView addSubview:logoImg];
        
        
        scroView.backgroundColor = [UIColor clearColor];
        UIView *superView = scroView;
        //*** put the userName and passWord textFields
        UIView *baseView = [[UIView alloc]init];
        //    UILabel *titleLabel = [[UILabel alloc]init];
        //    [logoImg addSubview:titleLabel];
        //    titleLabel.text = @"客户化手机端";
        //    titleLabel.textAlignment = NSTextAlignmentCenter;
        //    titleLabel.textColor = [UIColor colorWithHex:0x00a4fd];
        //    titleLabel.font = [UIFont systemFontOfSize:30];
        
        [logoImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(scroView.mas_centerX);
            make.top.equalTo(scroView.mas_top).offset(200/2);
            //        make.width.equalTo(self.view.mas_width);
            //        make.height.equalTo(@(66));
        }];
        
        //    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        //        make.centerX.equalTo(logoImg.mas_centerX);
        //        make.centerY.equalTo(logoImg.mas_centerY);
        //        make.width.equalTo(self.view.mas_width);
        //        make.height.equalTo(@(66));
        //    }];
        
        //    logoImg.image = [UIImage imageNamed:@"图层-1"];
        
        //***create user block view
        //    UIView *userView = [self createViewWithPlaceHolder:@"请输入账号" andImageName:@"data-拷贝" andTag:@"user" andTitle:@"账号"];
        UIView *userinterfaceView = [[UIView alloc] init];
        [baseView addSubview: userinterfaceView];
        userinterfaceView.layer.cornerRadius = 8.0f;
        userinterfaceView.layer.borderWidth = 2.0f;
        userinterfaceView.layer.borderColor = [UIColor colorWithHex:0xd3d3d3].CGColor;
        userinterfaceView.backgroundColor = [UIColor colorWithHex:0xe7e7e7];
        [userinterfaceView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(baseView.mas_left);
            make.top.equalTo(baseView.mas_top);
            make.right.equalTo(baseView.mas_right);
            make.height.equalTo(@((100+100+2+2+2)/2));
        }];
        UILabel *logoLb= [[UILabel alloc] init];
        [scroView addSubview:logoLb];
        logoLb.text = secondS;
        logoLb.textColor = [UIColor colorWithHex:0xef5152];
        logoLb.font = [UIFont systemFontOfSize:60/2];
        [logoLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(scroView.mas_centerX);
            make.top.equalTo(logoImg.mas_bottom).offset(30/2);
        }];
        UILabel *logoLb1= [[UILabel alloc] init];
        [scroView addSubview:logoLb1];
        logoLb1.text = firstS;
        logoLb1.textColor = [UIColor colorWithHex:0xef5152];
        logoLb1.font = [UIFont systemFontOfSize:60/2];
        [logoLb1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(logoLb.mas_left).offset(-20/2);
            make.top.equalTo(logoLb.mas_top);
        }];
        UILabel *logoLb2= [[UILabel alloc] init];
        [scroView addSubview:logoLb2];
        logoLb2.text = lastS;
        logoLb2.textColor = [UIColor colorWithHex:0xef5152];
        logoLb2.font = [UIFont systemFontOfSize:60/2];
        [logoLb2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(logoLb.mas_right).offset(20/2);
            make.top.equalTo(logoLb.mas_top);
        }];
        //    logoLb.backgroundColor = [UIColor greenColor];
        
        
        
        UIView *userView = [self createUserView:@"请输入账号" andImageName:@"index_out" andTag:@"user" andTitle:@""];
        [userinterfaceView addSubview:userView];
        
        //***create passWord view
        UIView *passView = [self createUserView:@"请输入登录密码" andImageName:@"index_password" andTag:@"pass" andTitle:@""];
        [userinterfaceView addSubview:passView];
        
        
        
        
        //***userView layout
        [userView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(userinterfaceView.mas_left);
            make.top.equalTo(userinterfaceView.mas_top);
            make.right.equalTo(userinterfaceView.mas_right);
            make.height.equalTo(@(100/2));
        }];
        
        //***passView layout
        [passView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(userView.mas_left);
            make.top.equalTo(userView.mas_bottom).offset(1);
            make.right.equalTo(userView.mas_right);
            make.height.equalTo(userView.mas_height);
        }];
        
        
        [superView addSubview:baseView];
        
        
        //***baseView layout
        [baseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(superView.mas_left).offset(36/2);
            make.top.equalTo(scroView.mas_bottom).offset(618/2);
            make.right.equalTo(self.view.mas_right).offset(-36/2);
            make.height.equalTo(@((100+100+42+90+3+4)/2));
        }];
        
        //***loginButton
        _loginBtn = [[UIButton alloc]init];
        [baseView addSubview:_loginBtn];
        
        UIButton *cancelBtn = [[UIButton alloc]init];
        [baseView addSubview:cancelBtn];
        //    [loginBtn setTitle:@"登陆" forState:UIControlStateNormal];
        //这里添加UI版本判断
        if ([getUIStyle() isEqualToString:STYLE0]) {
            [_loginBtn setBackgroundImage:[UIImage imageNamed:@"index_into_normal_Main"] forState:UIControlStateNormal];
            [_loginBtn setBackgroundImage:[UIImage imageNamed:@"index_into_press_Main"] forState:UIControlStateHighlighted];
        }else{
            [_loginBtn setBackgroundImage:[UIImage imageNamed:@"index_into_normal"] forState:UIControlStateNormal];
            [_loginBtn setBackgroundImage:[UIImage imageNamed:@"index_into_press"] forState:UIControlStateHighlighted];
        }
        
        //    [_loginBtn setBackgroundImage:[UIImage imageNamed:@"按钮_"] forState:UIControlStateNormal];
        //    [_loginBtn setImage:[UIImage imageNamed:@"登陆"] forState:UIControlStateHighlighted];
        [_loginBtn addTarget:self action:@selector(loginBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
        [_loginBtn setTitleColor:[UIColor colorWithHex:0xffffff] forState:UIControlStateNormal];
        
        //    [cancelBtn setImage:[UIImage imageNamed:@"取消"] forState:UIControlStateNormal];
        //    //    [loginBtn setImage:[UIImage imageNamed:@"登陆"] forState:UIControlStateHighlighted];
        //    [cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        //***baseView layout
        //    baseView.backgroundColor = [UIColor redColor];
        [_loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(baseView.mas_left);
            make.height.equalTo(@(90/2));
            make.right.equalTo(baseView.mas_right);
            make.top.equalTo(passView.mas_bottom).offset(65/2);
        }];
        
        
        [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(baseView.mas_left);
            make.height.equalTo(@(50));
            make.right.equalTo(baseView.mas_right);
            make.top.equalTo(_loginBtn.mas_bottom).offset(26);
        }];
        //***superView add response gesture to resignFirstResponse
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick)];
        [scroView addGestureRecognizer:tap];
        
        
        NSString *isLogin = [[NSUserDefaults standardUserDefaults]objectForKey:@"user"];
        NSString *pass = [[NSUserDefaults standardUserDefaults]objectForKey:@"pass"];
        if (isLogin)userNameText.text = isLogin;
        if(pass)passWordText.text = pass;
        
        
        exchangeBtn = [[UIButton alloc]init];
        [scroView addSubview:exchangeBtn];
        [exchangeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(scroView.mas_top).offset(40);
            make.right.equalTo(self.view.mas_right).offset(-10);
            make.width.equalTo(@(50));
            make.height.equalTo(@(30));
        }];
        
        [exchangeBtn setTitle:@"切换" forState:UIControlStateNormal];
        
        UILabel *buttomLabel = [[UILabel alloc] init];
        if (getEnglishLanguage()) {
            buttomLabel.text = @"©Copyright: Keweisoft";
        }else{
            NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
            NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];
            buttomLabel.text = [NSString stringWithFormat:@"©版权所有:悠季瑜伽 %@",app_build];
        }
        buttomLabel.textColor = [UIColor colorWithHex:0x858585];
        buttomLabel.font = [UIFont systemFontOfSize:22/2];
        [self.view addSubview:buttomLabel];
        [buttomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.view.mas_centerX);
            make.bottom.equalTo(self.view.mas_bottom).offset(-136/2);
        }];
        
        exchangeBtn.hidden = YES;
        //#pragma mark - 版本控制
        //#ifdef Main
        //    NSLog(@"主项目程序");
        //
        //    exchangeBtn.hidden = NO;
        //#elif Student
        //
        //    NSLog(@"学员端程序");
        //    //    [self dataRequest];
        //
        //    //    return YES;
        //    exchangeBtn.hidden = YES;
        //#elif Teacher
        //    //    rootview
        //    exchangeBtn.hidden = YES;
        //    NSLog(@"老师端程序");
        //#else
        //
        //    NSLog(@"都不是");
        //#endif
#pragma mark
        [exchangeBtn addTarget:self action:@selector(exchangeClick) forControlEvents:UIControlEventTouchUpInside];
        [exchangeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        if([getUIStyle() isEqualToString:STYLE0]){
            
            //[self createUIStyle0];
            //scroView.hidden = YES;
            _sv =[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0,KWIDTH, KHEIGHT)];
            [self.view addSubview:_sv];
            _sv.backgroundColor =[UIColor whiteColor];
            [self creatImages];
            _sv.contentSize = CGSizeMake(KWIDTH*3, KHEIGHT);
            _sv.pagingEnabled = YES;
            _sv.bounces = NO;
            _sv.hidden = YES;
            
            _sv.showsHorizontalScrollIndicator = NO;
            [self.view bringSubviewToFront:_sv];
            
        }
    }else{
        scroView = [[UIScrollView alloc]init];
        [self.view addSubview:scroView];
        
        [scroView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left);
            make.top.equalTo(self.view.mas_top);
            make.right.equalTo(self.view.mas_right);
            make.bottom.equalTo(self.view.mas_bottom);
        }];
        
        UIImageView *logoImg =[[UIImageView alloc]init];
        
        if ([getUIStyle() isEqualToString:STYLE0]) {
            logoImg.image = [UIImage imageNamed:@"hampson_tea"];
        }else{
            logoImg.image = [UIImage imageNamed:@"hampson_stu"];
        }
        
        
        
        [scroView addSubview:logoImg];
        
        
        scroView.backgroundColor = [UIColor clearColor];
        UIView *superView = scroView;
        //*** put the userName and passWord textFields
        UIView *baseView = [[UIView alloc]init];
        //    UILabel *titleLabel = [[UILabel alloc]init];
        //    [logoImg addSubview:titleLabel];
        //    titleLabel.text = @"客户化手机端";
        //    titleLabel.textAlignment = NSTextAlignmentCenter;
        //    titleLabel.textColor = [UIColor colorWithHex:0x00a4fd];
        //    titleLabel.font = [UIFont systemFontOfSize:30];
        
        [logoImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(scroView.mas_centerX);
            if ([getUIStyle() isEqualToString:STYLE0]) {
                make.top.equalTo(scroView.mas_top).offset(332/2);
            }else{
                make.top.equalTo(scroView.mas_top).offset(320/2);
            }
            
            //        make.width.equalTo(self.view.mas_width);
            //        make.height.equalTo(@(66));
        }];
        
        //    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        //        make.centerX.equalTo(logoImg.mas_centerX);
        //        make.centerY.equalTo(logoImg.mas_centerY);
        //        make.width.equalTo(self.view.mas_width);
        //        make.height.equalTo(@(66));
        //    }];
        
        //    logoImg.image = [UIImage imageNamed:@"图层-1"];
        
        //***create user block view
        //    UIView *userView = [self createViewWithPlaceHolder:@"请输入账号" andImageName:@"data-拷贝" andTag:@"user" andTitle:@"账号"];
        UIView *userinterfaceView = [[UIView alloc] init];
        [baseView addSubview: userinterfaceView];
        userinterfaceView.layer.cornerRadius = 8.0f;
        userinterfaceView.layer.borderWidth = 2.0f;
        userinterfaceView.layer.borderColor = [UIColor colorWithHex:0xd3d3d3].CGColor;
        userinterfaceView.backgroundColor = [UIColor colorWithHex:0xe7e7e7];
        [userinterfaceView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(baseView.mas_left);
            make.top.equalTo(baseView.mas_top);
            make.right.equalTo(baseView.mas_right);
            make.height.equalTo(@((100+100+2+2+2)/2));
        }];
        UILabel *logoLb= [[UILabel alloc] init];
        [scroView addSubview:logoLb];
        logoLb.text = secondS;
        logoLb.textColor = [UIColor colorWithHex:0xef5152];
        logoLb.font = [UIFont systemFontOfSize:60/2];
        [logoLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(scroView.mas_centerX);
            make.top.equalTo(logoImg.mas_bottom).offset(30/2);
        }];
        UILabel *logoLb1= [[UILabel alloc] init];
        [scroView addSubview:logoLb1];
        logoLb1.text = firstS;
        logoLb1.textColor = [UIColor colorWithHex:0xef5152];
        logoLb1.font = [UIFont systemFontOfSize:60/2];
        [logoLb1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(logoLb.mas_left).offset(-20/2);
            make.top.equalTo(logoLb.mas_top);
        }];
        UILabel *logoLb2= [[UILabel alloc] init];
        [scroView addSubview:logoLb2];
        logoLb2.text = lastS;
        logoLb2.textColor = [UIColor colorWithHex:0xef5152];
        logoLb2.font = [UIFont systemFontOfSize:60/2];
        [logoLb2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(logoLb.mas_right).offset(20/2);
            make.top.equalTo(logoLb.mas_top);
        }];
        
        //    logoLb.backgroundColor = [UIColor greenColor];
#pragma mark - 清除学员端或者教师端三个字
        logoLb.hidden = YES;
        logoLb1.hidden = YES;
        logoLb2.hidden = YES;
        UIView *userView;
        UIView *passView;
        if ([getUIStyle() isEqualToString:STYLE0]) {
            userView = [self createUserView:@"Phone Number" andImageName:@"index_out" andTag:@"user" andTitle:@""];
            passView = [self createUserView:@"PassWord" andImageName:@"index_password" andTag:@"pass" andTitle:@""];
        }else{
            userView = [self createUserView:@"请输入账号" andImageName:@"index_out" andTag:@"user" andTitle:@""];
            passView = [self createUserView:@"登录密码" andImageName:@"index_password" andTag:@"pass" andTitle:@""];
        }
        
        [userinterfaceView addSubview:userView];
        
        //***create passWord view
        
        [userinterfaceView addSubview:passView];
        
        
        
        
        //***userView layout
        [userView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(userinterfaceView.mas_left);
            make.top.equalTo(userinterfaceView.mas_top);
            make.right.equalTo(userinterfaceView.mas_right);
            make.height.equalTo(@(100/2));
        }];
        
        //***passView layout
        [passView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(userView.mas_left);
            make.top.equalTo(userView.mas_bottom).offset(1);
            make.right.equalTo(userView.mas_right);
            make.height.equalTo(userView.mas_height);
        }];
        
        
        [superView addSubview:baseView];
        
        
        //***baseView layout
        [baseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(superView.mas_left).offset(36/2);
            make.top.equalTo(scroView.mas_bottom).offset((124+320+172)/2);
            make.right.equalTo(self.view.mas_right).offset(-36/2);
            make.height.equalTo(@((100+100+42+90+3+4)/2));
        }];
        
        //***loginButton
        _loginBtn = [[UIButton alloc]init];
        [baseView addSubview:_loginBtn];
        
        UIButton *cancelBtn = [[UIButton alloc]init];
        [baseView addSubview:cancelBtn];
        //    [loginBtn setTitle:@"登陆" forState:UIControlStateNormal];
        [_loginBtn setBackgroundImage:[UIImage imageNamed:@"index_into_normal"] forState:UIControlStateNormal];
        [_loginBtn setBackgroundImage:[UIImage imageNamed:@"index_into_press"] forState:UIControlStateHighlighted];
        //    [_loginBtn setBackgroundImage:[UIImage imageNamed:@"按钮_"] forState:UIControlStateNormal];
        //    [_loginBtn setImage:[UIImage imageNamed:@"登陆"] forState:UIControlStateHighlighted];
        [_loginBtn addTarget:self action:@selector(loginBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        if ([getUIStyle() isEqualToString:STYLE0]) {
            [_loginBtn setTitle:@"Login" forState:UIControlStateNormal];
        }else{
            [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
        }
        
        [_loginBtn setTitleColor:[UIColor colorWithHex:0xffffff] forState:UIControlStateNormal];
        
        //    [cancelBtn setImage:[UIImage imageNamed:@"取消"] forState:UIControlStateNormal];
        //    //    [loginBtn setImage:[UIImage imageNamed:@"登陆"] forState:UIControlStateHighlighted];
        //    [cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        //***baseView layout
        //    baseView.backgroundColor = [UIColor redColor];
        [_loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(baseView.mas_left);
            make.height.equalTo(@(90/2));
            make.right.equalTo(baseView.mas_right);
            make.top.equalTo(passView.mas_bottom).offset(65/2);
        }];
        
        
        [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(baseView.mas_left);
            make.height.equalTo(@(50));
            make.right.equalTo(baseView.mas_right);
            make.top.equalTo(_loginBtn.mas_bottom).offset(26);
        }];
        //***superView add response gesture to resignFirstResponse
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick)];
        [scroView addGestureRecognizer:tap];
        
        
        NSString *isLogin = [[NSUserDefaults standardUserDefaults]objectForKey:@"user"];
        NSString *pass = [[NSUserDefaults standardUserDefaults]objectForKey:@"pass"];
        if (isLogin)userNameText.text = isLogin;
        if(pass)passWordText.text = pass;
        
        
        exchangeBtn = [[UIButton alloc]init];
        [scroView addSubview:exchangeBtn];
        [exchangeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(scroView.mas_top).offset(40);
            make.right.equalTo(self.view.mas_right).offset(-10);
            make.width.equalTo(@(50));
            make.height.equalTo(@(30));
        }];
        
        [exchangeBtn setTitle:@"切换" forState:UIControlStateNormal];
        
        UILabel *buttomLabel = [[UILabel alloc] init];
        if (getEnglishLanguage()) {
            buttomLabel.text = @"©Copyright: Keweisoft";
        }else{
            NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
            NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];
            buttomLabel.text = [NSString stringWithFormat:@"©版权所有:悠季瑜伽 %@",app_build];
        }
        buttomLabel.textColor = [UIColor colorWithHex:0x858585];
        buttomLabel.font = [UIFont systemFontOfSize:22/2];
        [self.view addSubview:buttomLabel];
        [buttomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.view.mas_centerX);
            make.bottom.equalTo(self.view.mas_bottom).offset(-136/2);
        }];
        
        exchangeBtn.hidden = YES;
        //#pragma mark - 版本控制
        //#ifdef Main
        //    NSLog(@"主项目程序");
        //
        //    exchangeBtn.hidden = NO;
        //#elif Student
        //
        //    NSLog(@"学员端程序");
        //    //    [self dataRequest];
        //
        //    //    return YES;
        //    exchangeBtn.hidden = YES;
        //#elif Teacher
        //    //    rootview
        //    exchangeBtn.hidden = YES;
        //    NSLog(@"老师端程序");
        //#else
        //
        //    NSLog(@"都不是");
        //#endif
#pragma mark
        [exchangeBtn addTarget:self action:@selector(exchangeClick) forControlEvents:UIControlEventTouchUpInside];
        [exchangeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
        NSString *needSv = [ud objectForKey:@"NEEDSV"];//是否需要引导页
        BOOL isOK = ![needSv isEqualToString:@"NO"];
        if(isOK){
            
            //[self createUIStyle0];
            scroView.hidden = YES;
            _sv =[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0,KWIDTH, KHEIGHT)];
            [self.view addSubview:_sv];
            _sv.backgroundColor =[UIColor whiteColor];
            [self creatImages];
            _sv.contentSize = CGSizeMake(KWIDTH*3, KHEIGHT);
            _sv.pagingEnabled = YES;
            _sv.bounces = NO;
            _sv.showsHorizontalScrollIndicator = NO;
            [self.view bringSubviewToFront:_sv];
            
        }
        
    }
    
    
}


/*
 //#elif Student
 -(void)createUIStyle1{
 //***superView is all the base View
 scroView = [[UIScrollView alloc]init];
 [self.view addSubview:scroView];
 
 [scroView mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(self.view.mas_left);
 make.top.equalTo(self.view.mas_top);
 make.right.equalTo(self.view.mas_right);
 make.bottom.equalTo(self.view.mas_bottom);
 }];
 
 UIImageView *logoImg =[[UIImageView alloc]init];
 
 logoImg.image = [UIImage imageNamed:@"index_logo"];
 
 [scroView addSubview:logoImg];
 
 
 scroView.backgroundColor = [UIColor clearColor];
 UIView *superView = scroView;
 //*** put the userName and passWord textFields
 UIView *baseView = [[UIView alloc]init];
 //    UILabel *titleLabel = [[UILabel alloc]init];
 //    [logoImg addSubview:titleLabel];
 //    titleLabel.text = @"客户化手机端";
 //    titleLabel.textAlignment = NSTextAlignmentCenter;
 //    titleLabel.textColor = [UIColor colorWithHex:0x00a4fd];
 //    titleLabel.font = [UIFont systemFontOfSize:30];
 
 [logoImg mas_makeConstraints:^(MASConstraintMaker *make) {
 make.centerX.equalTo(scroView.mas_centerX);
 make.top.equalTo(scroView.mas_top).offset(200/2);
 //        make.width.equalTo(self.view.mas_width);
 //        make.height.equalTo(@(66));
 }];
 
 //    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
 //        make.centerX.equalTo(logoImg.mas_centerX);
 //        make.centerY.equalTo(logoImg.mas_centerY);
 //        make.width.equalTo(self.view.mas_width);
 //        make.height.equalTo(@(66));
 //    }];
 
 //    logoImg.image = [UIImage imageNamed:@"图层-1"];
 
 //***create user block view
 //    UIView *userView = [self createViewWithPlaceHolder:@"请输入账号" andImageName:@"data-拷贝" andTag:@"user" andTitle:@"账号"];
 UIView *userinterfaceView = [[UIView alloc] init];
 [baseView addSubview: userinterfaceView];
 userinterfaceView.layer.cornerRadius = 8.0f;
 userinterfaceView.layer.borderWidth = 2.0f;
 userinterfaceView.layer.borderColor = [UIColor colorWithHex:0xd3d3d3].CGColor;
 userinterfaceView.backgroundColor = [UIColor colorWithHex:0xe7e7e7];
 [userinterfaceView mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(baseView.mas_left);
 make.top.equalTo(baseView.mas_top);
 make.right.equalTo(baseView.mas_right);
 make.height.equalTo(@((100+100+2+2+2)/2));
 }];
 UILabel *logoLb= [[UILabel alloc] init];
 [scroView addSubview:logoLb];
 logoLb.text = @"员";
 logoLb.textColor = [UIColor colorWithHex:0xef5152];
 logoLb.font = [UIFont systemFontOfSize:60/2];
 [logoLb mas_makeConstraints:^(MASConstraintMaker *make) {
 make.centerX.equalTo(scroView.mas_centerX);
 make.top.equalTo(logoImg.mas_bottom).offset(30/2);
 }];
 UILabel *logoLb1= [[UILabel alloc] init];
 [scroView addSubview:logoLb1];
 logoLb1.text = @"学";
 logoLb1.textColor = [UIColor colorWithHex:0xef5152];
 logoLb1.font = [UIFont systemFontOfSize:60/2];
 [logoLb1 mas_makeConstraints:^(MASConstraintMaker *make) {
 make.right.equalTo(logoLb.mas_left).offset(-20/2);
 make.top.equalTo(logoLb.mas_top);
 }];
 UILabel *logoLb2= [[UILabel alloc] init];
 [scroView addSubview:logoLb2];
 logoLb2.text = @"端";
 logoLb2.textColor = [UIColor colorWithHex:0xef5152];
 logoLb2.font = [UIFont systemFontOfSize:60/2];
 [logoLb2 mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(logoLb.mas_right).offset(20/2);
 make.top.equalTo(logoLb.mas_top);
 }];
 //    logoLb.backgroundColor = [UIColor greenColor];
 
 
 
 UIView *userView = [self createUserView:@"请输入账号" andImageName:@"index_out" andTag:@"user" andTitle:@""];
 [userinterfaceView addSubview:userView];
 
 //***create passWord view
 UIView *passView = [self createUserView:@"请输入登录密码" andImageName:@"index_password" andTag:@"pass" andTitle:@""];
 [userinterfaceView addSubview:passView];
 
 
 
 
 //***userView layout
 [userView mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(userinterfaceView.mas_left);
 make.top.equalTo(userinterfaceView.mas_top);
 make.right.equalTo(userinterfaceView.mas_right);
 make.height.equalTo(@(100/2));
 }];
 
 //***passView layout
 [passView mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(userView.mas_left);
 make.top.equalTo(userView.mas_bottom).offset(1);
 make.right.equalTo(userView.mas_right);
 make.height.equalTo(userView.mas_height);
 }];
 
 
 [superView addSubview:baseView];
 
 
 //***baseView layout
 [baseView mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(superView.mas_left).offset(36/2);
 make.top.equalTo(scroView.mas_bottom).offset(618/2);
 make.right.equalTo(self.view.mas_right).offset(-36/2);
 make.height.equalTo(@((100+100+42+90+3+4)/2));
 }];
 
 //***loginButton
 _loginBtn = [[UIButton alloc]init];
 [baseView addSubview:_loginBtn];
 
 UIButton *cancelBtn = [[UIButton alloc]init];
 [baseView addSubview:cancelBtn];
 //    [loginBtn setTitle:@"登陆" forState:UIControlStateNormal];
 [_loginBtn setBackgroundImage:[UIImage imageNamed:@"index_into_normal"] forState:UIControlStateNormal];
 [_loginBtn setBackgroundImage:[UIImage imageNamed:@"index_into_press"] forState:UIControlStateHighlighted];
 //    [_loginBtn setBackgroundImage:[UIImage imageNamed:@"按钮_"] forState:UIControlStateNormal];
 //    [_loginBtn setImage:[UIImage imageNamed:@"登陆"] forState:UIControlStateHighlighted];
 [_loginBtn addTarget:self action:@selector(loginBtnClick:) forControlEvents:UIControlEventTouchUpInside];
 
 [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
 [_loginBtn setTitleColor:[UIColor colorWithHex:0xffffff] forState:UIControlStateNormal];
 
 //    [cancelBtn setImage:[UIImage imageNamed:@"取消"] forState:UIControlStateNormal];
 //    //    [loginBtn setImage:[UIImage imageNamed:@"登陆"] forState:UIControlStateHighlighted];
 //    [cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
 
 //***baseView layout
 //    baseView.backgroundColor = [UIColor redColor];
 [_loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(baseView.mas_left);
 make.height.equalTo(@(90/2));
 make.right.equalTo(baseView.mas_right);
 make.top.equalTo(passView.mas_bottom).offset(65/2);
 }];
 
 
 [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(baseView.mas_left);
 make.height.equalTo(@(50));
 make.right.equalTo(baseView.mas_right);
 make.top.equalTo(_loginBtn.mas_bottom).offset(26);
 }];
 //***superView add response gesture to resignFirstResponse
 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick)];
 [scroView addGestureRecognizer:tap];
 
 
 NSString *isLogin = [[NSUserDefaults standardUserDefaults]objectForKey:@"user"];
 NSString *pass = [[NSUserDefaults standardUserDefaults]objectForKey:@"pass"];
 if (isLogin)userNameText.text = isLogin;
 if(pass)passWordText.text = pass;
 
 
 exchangeBtn = [[UIButton alloc]init];
 [scroView addSubview:exchangeBtn];
 [exchangeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
 make.top.equalTo(scroView.mas_top).offset(40);
 make.right.equalTo(self.view.mas_right).offset(-10);
 make.width.equalTo(@(50));
 make.height.equalTo(@(30));
 }];
 
 [exchangeBtn setTitle:@"切换" forState:UIControlStateNormal];
 
 UILabel *buttomLabel = [[UILabel alloc] init];
 buttomLabel.text = @"©版权所有:可为时代";
 buttomLabel.textColor = [UIColor colorWithHex:0x858585];
 buttomLabel.font = [UIFont systemFontOfSize:22/2];
 [self.view addSubview:buttomLabel];
 [buttomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
 make.centerX.equalTo(self.view.mas_centerX);
 make.bottom.equalTo(self.view.mas_bottom).offset(-136/2);
 }];
 
 exchangeBtn.hidden = YES;
 //#pragma mark - 版本控制
 //#ifdef Main
 //    NSLog(@"主项目程序");
 //
 //    exchangeBtn.hidden = NO;
 //#elif Student
 //
 //    NSLog(@"学员端程序");
 //    //    [self dataRequest];
 //
 //    //    return YES;
 //    exchangeBtn.hidden = YES;
 //#elif Teacher
 //    //    rootview
 //    exchangeBtn.hidden = YES;
 //    NSLog(@"老师端程序");
 //#else
 //
 //    NSLog(@"都不是");
 //#endif
 #pragma mark
 [exchangeBtn addTarget:self action:@selector(exchangeClick) forControlEvents:UIControlEventTouchUpInside];
 [exchangeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
 }*/
//#else
//
//#endif

#pragma mark - 清空userdefault
- (void)resetDefaults {
    
    NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
    
    NSDictionary* dict = [defs dictionaryRepresentation];
    
    for(id key in dict) {
        
        [defs removeObjectForKey:key];
        
    }
    
    [defs synchronize];
    
}



-(void)exchangeClick{
    
    actionsheet = [[UIActionSheet alloc]init];
    actionsheet.delegate = self;
    for (ProjectModel *model in _projectArr) {
        NSString *proStr = [NSString stringWithFormat:@"%@", model.programa_name];
        
        [actionsheet addButtonWithTitle:proStr];
    }
    
    [actionsheet showInView:self.view];
    
    //[self dismissViewControllerAnimated:YES completion:^{
    //
    //}];
}
-(void)cancelBtnClick{
    
}

#pragma mark - tapClickToResponseTextField
-(void)tapClick{
    [focusTextField resignFirstResponder];
}


#pragma mark - loginButton click
-(void)loginBtnClick:(UIButton *)btn{
    if(self.requeatResultLabel){
        NSLog(@"aaaaaolololol");
        [self.requeatResultLabel removeFromSuperview];}
    
    if(focusTextField){
        [focusTextField resignFirstResponder];
    }
    
    if (userNameText.text.length == 0 || passWordText.text.length == 0) {
        
        NSString *tipsString;
        NSString *warning;
        NSString *cancelS;
        if ([getUserType() isEqualToString:UserISHPSTeacher]) {
            tipsString = @"Input the correct username and password";
            warning = @"warning";
            cancelS = @"Cancel";
            
        }else{
            tipsString = @"请输入正确格式用户名密码";
            warning = @"警告";
            cancelS = @"取消";
        }
        
        float version=[[[UIDevice currentDevice] systemVersion] floatValue];
        if (version<9) {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:warning message:tipsString delegate:self cancelButtonTitle:cancelS otherButtonTitles:nil, nil];
            [alert show];
        }else{
            // ssssss
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:warning message:tipsString preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelS style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            [alertController addAction:cancelAction];
            [self presentViewController:alertController animated:YES completion:^{
                
            }];
        }
        return;
    }
    
    
    NSString *savedStr = userName();
    NSString *saveStra = passWord();
    
    
    //*** 为了取出时间戳 之后会做处理以更改取出时间戳的方式
    
    NSLog(@"%@", userName());
    NSString *filename=getSaveFile(userName(),LOGINFOUNCTION);   //获取路径
    NSString *path=[filename stringByAppendingPathComponent:@"loginOK.plist"];
    
    NSData *dataNow = [NSData dataWithContentsOfFile:path];
    NSDictionary * dic;
    if(dataNow){
        
        dic = [NSJSONSerialization JSONObjectWithData:dataNow options:NSJSONReadingMutableContainers error:nil];  //读取数据
    }
    //*** 设置传递参数
    NSMutableDictionary *parmas = [[NSMutableDictionary alloc]init];
    [parmas setObject:userNameText.text forKey:@"loginName"];
    [parmas setObject:passWordText.text forKey:@"password"];
    [parmas setObject:@"1" forKey:@"source"];
    if (!proID) {
        [self getProId];
        //[self showLabelWithText:@"无网络，请稍后重试"];
        return;
    }
    [parmas setObject:proID forKey:@"proId"];
    
    if([dic valueForKey:@"alterTime"]&&[userName() isEqualToString:userNameText.text]&&0){
        
        //[parmas setObject:[dic valueForKey:@"alterTime"] forKey:@"alterTime"];
    }else{
        [parmas setObject:@"" forKey:@"alterTime"];
        
    }
    //    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    //    if([userDefault valueForKey:PROGRAMA])self.programaUrl = [NSString stringWithFormat:@"%@", [userDefault valueForKey:PROGRAMA]];roleFollowList   self.programaUrl
    //
    //__weak typeof(self) weakSelf = self;
    
    NSString *requestStr =[NSString stringWithFormat:@"%@%@", getBase(), LOGIN_URL];
    btn.enabled = NO;
    exchangeBtn.enabled = NO;
    
    //[BQActivityView showActiviTy];
    _indicator = [[JQIndicatorView alloc] initWithType:2 tintColor:[UIColor colorWithHex:0xef5152]];
    _indicator.center = self.view.center;
    [self.view addSubview:_indicator];
    [_indicator startAnimating];
    
    [NetRequest requestUrl:requestStr andParamas:parmas andReturnBlock:^(NSData *data, NSError *error) {
        if(!error&&data!=nil){
            [_indicator stopAnimating];
            //[BQActivityView hideActiviTy];
            NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            
            NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
            
            //这里添加了角色判断   貌似没用
            //if ([getUserType() isEqualToString:UserISHPSStudent]||[getUserType() isEqualToString:UserISHPSTeacher]) {
            // _sharedNSTimer = [LoginViewController sharedNSTimer];
            // [_sharedNSTimer fire];
            // _sharedNSTimer = [NSTimer scheduledTimerWithTimeInterval:600.0f target:self selector:@selector(scrollTimer) userInfo:nil repeats:NO];
            // NSDate *date = [NSDate date];
            // NSDate *fireDate = [NSDate dateWithTimeInterval:600.0f sinceDate:date];
            // [_sharedNSTimer setFireDate:fireDate];
            // _sharedNSTimer = [LoginViewController sharedNSTimer];
            //  }else{
            
            // }
            
            
            
            //[_myTimer fire];
            
            //*** error message
            NSString * errorStr = [NSString stringWithFormat:@"%@", [obj valueForKey:@"error"]];
            if ([errorStr isEqualToString:@"1"]) {
                [self showLabelWithText:[NSString stringWithFormat:@"%@", [obj valueForKey:@"errorMsg"]]];
                btn.enabled = YES;
                exchangeBtn.enabled = YES;
                [_indicator stopAnimating];
            }else{//可以登录
                
                
                //            NSString *appDomain = [[NSBundle mainBundle]bundleIdentifier];
                //
                //            [userDefault removePersistentDomainForName:appDomain];//登录成功后清除上个人员的相关数据
                [userDefault synchronize];
                [_indicator stopAnimating];
                
                
                
                
                
                
                
                //*** save feed back user message
                saveUserNameDes([[obj objectForKey:@"loginInfo"]objectForKey:@"USERNAME"]);
                saveUserId([[obj objectForKey:@"loginInfo"]objectForKey:@"USERID"]);
                saveSessionId([[obj objectForKey:@"loginInfo"]objectForKey:@"sessionId"]);
                
                NSString *roleNames =[[obj objectForKey:@"loginInfo"]objectForKey:@"roleNames"];
                
                saveUserDisDes(roleNames);
                //                [userDefault setObject:roleNames forKey:@"roleNames"];
                //                [userDefault synchronize];
                
                
                if([obj valueForKey:@"notMsgCount"]){
                    NSLog(@"notMsgCount:%zd",[[obj valueForKey:@"notMsgCount"] intValue]);
                    NSInteger badge = [[obj valueForKey:@"notMsgCount"] integerValue];
                    NSUserDefaults * ud1 = [NSUserDefaults standardUserDefaults];
                    [ud1 setObject:[NSString stringWithFormat:@"%zd",badge] forKey:@"badge"];
                    [UIApplication sharedApplication].applicationIconBadgeNumber = badge;
                }
                
                
                if([obj valueForKey:@"alterTime"]){
                    
                    [userDefault setObject:[obj valueForKey:@"buttons"] forKey:BUTTON_STRING];
                    [userDefault synchronize];
                    
                    //*** save feed back message
                    NSString *path2= myselfSaveFile(userNameText.text, LOGINFOUNCTION, @"login.plist");
                    
                    NSString *path3 = [path2 stringByAppendingPathComponent:LOGINOK];
                    
                    BOOL succeed = [data writeToFile:path3 atomically:YES];
                    if (succeed) {
                        NSLog(@"-------------- catch ---- 缓存成功");
                    }else{
                        NSLog(@"%@", @"缓存失败");
                    }
                    //re =
                }
                if([[obj valueForKey:@"loginInfo"] valueForKey:@"USERID"])
                {
                    NSLog(@"%@",[[obj valueForKey:@"loginInfo"] valueForKey:@"USERID"]);
                    NSString *alias = [NSString stringWithFormat:@"%@",[[obj valueForKey:@"loginInfo"] valueForKey:@"USERID"]];
                    NSLog(@"%@",alias);
                    [JPUSHService setTags:nil alias:alias fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) {
                        NSLog(@"%i",iResCode);
                    }];
                }
                
                //                if (re) {
                NSLog(@"ok");
                
                //*** write success
#pragma -mark 通知中心
                
                
                //if (!userIcon()) {
                
                //}else{
                //    NSNotificationCenter *noti = [NSNotificationCenter defaultCenter];
                //    saveLoginState(LOGSTATE);
                //    [noti postNotificationName:@"login" object:@"loginSuccees"];
                
                
                //*** save succeed the user name password for remember
                //    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
                //    saveUserName(userNameText.text);
                //    savePassWord(passWordText.text);
                //    saveLoginState(@"yes");
                //    [userDefault setObject:@"yes" forKey:@"isLogin"];
                //    [userDefault setObject:[[obj objectForKey:@"loginInfo"] objectForKey:@"USERID"] forKey:@"USERID"];//STUID 修改成USERID
                //    NSString *str =[obj objectForKey:@"loginInfo"];
                //    [userDefault synchronize];
                //}
                
                NSString *userName2 = userName();
                NSLog(@"%@",userName2);
                if (userName2) {
                    if ([userName() isEqualToString:userNameText.text]) {
                        NSLog(@"同一个人登录，不需要更新账户信息");
                        saveUserIfChange(@"NO");
                    }else{
                        NSLog(@"更换用户，需要处理相关个人信息内容");
                        [userDefault removeObjectForKey:@"userIcon"];
                        
#pragma mark - 这里是标记是否切换用户的标记：YES表示更换了，NO表示没更换
                        //getUserChange()//这个方法获取值
                        
                        saveUserIfChange(@"YES");
                        
                        
                        [userDefault removeObjectForKey:@"PersonDic"];//登录成功后清除上个人员的相关数据
                        [userDefault removeObjectForKey:@"FeedBackDic"];//登录成功后清除上个人员的相关数据
                    }
                    
                }else{
                    saveUserIfChange(@"YES");
                }
                if ([obj objectForKey:@"personInfoList"]) {//hideMenuList
                    NSArray *hidenArr = [obj objectForKey:@"personInfoList"];
                    for (NSDictionary *dic in hidenArr) {
                        //NSString *menuNameStr = [dic objectForKey:@"menuName"];
                        //NSRange range = [menuNameStr rangeOfString:@"个人资料"];
                        //if (range.length>0) {
                        savePersonDic(dic);
                        //}
                        /**  NSRange range1 = [menuNameStr rangeOfString:@"反馈"];
                         if (range1.length>0) {
                         saveFeedBackDic(dic);
                         }
                         */
                    }
                    
                    
                    
                }
                if ([obj objectForKey:@"feedbackInfoList"]) {//hideMenuList
                    NSArray *hidenArr = [obj objectForKey:@"feedbackInfoList"];
                    for (NSDictionary *dic in hidenArr) {
                        /*    NSString *menuNameStr = [dic objectForKey:@"menuName"];
                         NSRange range = [menuNameStr rangeOfString:@"个人资料"];
                         if (range.length>0) {
                         savePersonDic(dic);
                         }
                         
                         */
                        //NSRange range1 = [menuNameStr rangeOfString:@"反馈"];
                        //if (range1.length>0) {
                        saveFeedBackDic(dic);
                        //}
                    }
                    
                    
                }
                
                
                [userDefault setObject:@"autoLoginS" forKey:@"autoLogin"];
                
                //这里添加功能判断
                if(getAvatarUpload())
                {
                    if ([obj objectForKey:@"teaMongoId"]) {
                        
                        
                        
                        NSString *paths = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
                        NSLog(@"%@",paths);
                        NSFileManager *fileMgr = [NSFileManager defaultManager];
                        NSMutableString *usericon = [[NSMutableString alloc]initWithString:paths];
                        if (userId()) {
                            [usericon appendString:[NSString stringWithFormat:@"//images//%@",userId()]];
                        }else{
                            [usericon appendString:[NSString stringWithFormat:@"//images//%@",@"头像1"]];
                        }
                        BOOL bRet = [fileMgr fileExistsAtPath:usericon];
                        NSMutableDictionary *diction = userIconMongodbId();
                        NSString *strKey = [NSString stringWithFormat:@"%@",userId()];
                        NSString *oldMonId = [diction objectForKey:strKey];
                        NSString * teaMongoId = [NSString stringWithFormat:@"%@",[obj objectForKey:@"teaMongoId"]];
                        if ([oldMonId isEqualToString:teaMongoId]) {
                            
                            
                            
                            
                            
                            
                            
                            
                            if (bRet) {
                                //
                                
                                //                        [fileMgr removeItemAtPath:usericon error:&err];
                            }
                            
                            NSError *err;
                            
                            //                            BOOL bRemove = [fileMgr removeItemAtPath:usericon error:&err];
                            
                            if (bRet) {//判断该用户是否有存过头像，有文件不需要下载，说明可以去，取出头像文件位置
                                
                                saveUserIcon(usericon);
                                NSNotificationCenter *noti = [NSNotificationCenter defaultCenter];
                                saveLoginState(LOGSTATE);
                                [noti postNotificationName:@"login" object:@"loginSuccees"];
                                
                                //                        NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
                                saveUserName(userNameText.text);
                                savePassWord(passWordText.text);
                                saveLoginState(@"yes");
                                [userDefault setObject:@"yes" forKey:@"isLogin"];
                                [userDefault setObject:[[obj objectForKey:@"loginInfo"] objectForKey:@"USERID"] forKey:@"USERID"];//STUID 修改成USERID
                                NSString *str =[obj objectForKey:@"loginInfo"];
                                [userDefault synchronize];
                                
                                
                            }else{//没存过表示新用户，需要下载，走这里
                                //这里添加了角色判断
                                NSLog(@"%@",err);
                                if ([getUserType() isEqualToString:UserISHPSTeacher]) {
                                    //    if([getUIStyle() isEqualToString:STYLE0]){
                                    //if ([obj objectForKey:@"teaMongoId"]) {
                                    
                                    
                                    [self requestUserIconAndSave:teaMongoId andNSDictionary:obj];
                                    //}else
                                    //{
                                    //   [self LoginSystem:obj andBtn:btn];
                                    //}
                                    
                                }else{
                                    // [self LoginSystem:obj andBtn:btn];
                                }
                            }
                            
                        }else{
                            if ([[obj objectForKey:@"teaMongoId"] isEqualToString:@""]) {
                                [self LoginSystem:obj andBtn:btn];
                                return;
                            }
                            NSError *err;
                            BOOL bRemove = [fileMgr removeItemAtPath:usericon error:&err];
                            if (bRemove) {
                                [self requestUserIconAndSave:teaMongoId andNSDictionary:obj];
                            }else{
                                [self requestUserIconAndSave:teaMongoId andNSDictionary:obj];
                            }
                            return;
                        }
                    }else{//返回的键值中不包含teaMongodbId不能下载头像
                        NSString *oldMonId = [userIconMongodbId() objectForKey:userId()];
                        NSString *paths = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
                        NSLog(@"%@",paths);
                        NSFileManager *fileMgr = [NSFileManager defaultManager];
                        NSMutableString *usericon = [[NSMutableString alloc]initWithString:paths];
                        if (userId()) {
                            [usericon appendString:[NSString stringWithFormat:@"//images//%@",userId()]];
                        }else{
                            [usericon appendString:[NSString stringWithFormat:@"//images//%@",@"头像1"]];
                        }
                        BOOL bRet = [fileMgr fileExistsAtPath:usericon];
                        if (bRet) {//判断该用户是否有存过头像，有文件不需要下载，说明可以去，取出头像文件位置
                            
                            saveUserIcon(usericon);
                            NSNotificationCenter *noti = [NSNotificationCenter defaultCenter];
                            saveLoginState(LOGSTATE);
                            [noti postNotificationName:@"login" object:@"loginSuccees"];
                            
                            //                        NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
                            saveUserName(userNameText.text);
                            savePassWord(passWordText.text);
                            saveLoginState(@"yes");
                            [userDefault setObject:@"yes" forKey:@"isLogin"];
                            [userDefault setObject:[[obj objectForKey:@"loginInfo"] objectForKey:@"USERID"] forKey:@"USERID"];//STUID 修改成USERID
                            NSString *str =[obj objectForKey:@"loginInfo"];
                            [userDefault synchronize];
                            
                            
                        }else{//没存过表示新用户，需要下载，走这里
                            //这里添加了角色判断
                            //NSLog(@"%@",err);
                            if ([getUserType() isEqualToString:UserISHPSTeacher]) {
                                //    if([getUIStyle() isEqualToString:STYLE0]){
                                //if ([obj objectForKey:@"teaMongoId"]) {
                                
                                
                                [self requestUserIconAndSave:oldMonId andNSDictionary:obj];
                                //}else
                                //{
                                //   [self LoginSystem:obj andBtn:btn];
                                //}
                                
                            }else{
                                // [self LoginSystem:obj andBtn:btn];
                            }
                        }
                        
                    }
                }
                
                
                
                
                [self LoginSystem:obj andBtn:btn];
                
                
                
                
                
                
                
                
            }
            //            NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
        }
        else{
            //*** connect failed find wheather requested the user data if have use it
            if([savedStr isEqualToString:userNameText.text]&&[saveStra isEqualToString:passWordText.text]&&savedStr!=nil&&saveStra!=nil&&userNameText.text!=nil&&passWordText.text!=nil){
                [self LoginSystem:nil andBtn:btn];
            }
            NSString *str = [NSString stringWithFormat:@"%@", error.localizedDescription];
            
            [self showLabelWithText:str];
            btn.enabled = YES;
            exchangeBtn.enabled = YES;
            [_indicator stopAnimating];
        }
        
        exchangeBtn.enabled = YES;
    }];
    
    
}


#pragma mark - create block with textField and ingView
-(UIView *)createViewWithPlaceHolder:(NSString *)placeHolder andImageName:(NSString *)imageName andTag:(NSString *)tag andTitle:(NSString*)titleStr{
    UIView *baseView = [[UIView alloc]init];
    baseView.backgroundColor = [UIColor whiteColor];
    
    UIImageView *imgView = [[UIImageView alloc]init];
    [baseView addSubview:imgView];
    
    UILabel *la = [[UILabel alloc]init];
    [baseView addSubview:la];
    
    
    UITextField *textField = [[UITextField alloc]init];
    textField.delegate = self;
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [baseView addSubview:textField];
    
    [la mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(baseView.mas_left);
        make.centerY.equalTo(baseView.mas_centerY);
        make.width.equalTo(@(40));
        make.height.equalTo(IMGTEXTGEI);
    }];
    [la sizeToFit];
    //    la.backgroundColor = [UIColor redColor];
    
    la.textColor = [UIColor colorWithRed:0x5b/255.0 green:0x5b/255.0 blue:0x5b/255.0 alpha:1];
    la.font = [UIFont systemFontOfSize:32/2];
    
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(la.mas_right).offset(92/2);
        make.centerY.equalTo(la.mas_centerY);
        make.right.equalTo(baseView.mas_right);
        make.height.equalTo(IMGTEXTGEI);
    }];
    
    //    [la mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.equalTo(baseView.mas_left);
    //        make.bottom.equalTo(baseView.mas_bottom).offset(-1);
    //        make.width.equalTo(@(35/2));
    //        make.height.equalTo(@(39/2));
    //    }];
    
    UIImageView *imgLine = [[UIImageView alloc]init];
    [baseView addSubview:imgLine];
    [imgLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(baseView.mas_left);
        make.right.equalTo(baseView.mas_right);
        make.bottom.equalTo(baseView.mas_bottom);
        make.height.equalTo(@(1));
    }];
    imgLine.backgroundColor = [UIColor colorWithHex:0xd1d1d1];
    
    la.text = titleStr;
    la.font = [UIFont systemFontOfSize:17];
    imgView.image = [UIImage imageNamed:imageName];
    textField.placeholder = placeHolder;
    if ([tag isEqualToString:@"user"]) {
        userNameText = textField;
    }else if ([tag isEqualToString:@"pass"]) {
        passWordText = textField;
        passWordText.secureTextEntry = YES;
    }
    
    return baseView;
}



#pragma mark - UITextFieldDelegate
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    focusTextField = textField;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return NO;
}


#pragma mark - UIActionSheetDelegate
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    ProjectModel *model = _projectArr[buttonIndex];
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    [userDefault setObject:model.proId forKey:PROID];
    [userDefault setObject:model.programa_url forKey:PROGRAMA];
    [userDefault setObject:model.pro_port forKey:PORT];
    
    
    saveUIStyle([NSString stringWithFormat:@"%ld", buttonIndex%2]);
    
    [userDefault synchronize];
    proID = [userDefault valueForKey:PROID];
    
}
#pragma mark - sub from other class
-(void)showLabelWithText:(NSString *)text{
    if(self.requeatResultLabel!=nil)return;
    self.requeatResultLabel = [[UILabel alloc]init];
    self.requeatResultLabel.backgroundColor = [UIColor colorWithRed:30/255.0 green:25/255.0 blue:77/255.0 alpha:0.4];
    self.requeatResultLabel.textColor = [UIColor whiteColor];
    self.requeatResultLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:self.requeatResultLabel];
    self.requeatResultLabel.frame = CGRectMake(0, 0, self.view.bounds.size.width, 0);
    CGRect frame = self.requeatResultLabel.frame;
    self.requeatResultLabel.text = [NSString stringWithFormat:@"%@", text];
    self.requeatResultLabel.font = [UIFont systemFontOfSize:14];
    [self.view bringSubviewToFront:self.requeatResultLabel];
    [UIView animateWithDuration:1 animations:^{
        self.requeatResultLabel.frame = CGRectMake(0, 20, self.view.bounds.size.width, 25);
        
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:1 animations:^{
            self.requeatResultLabel.frame = frame;
        } completion:^(BOOL finished) {
            [self.requeatResultLabel removeFromSuperview];
            self.requeatResultLabel = nil;
        }];
    }];
    
}


-(void)requestUserIconAndSave:(NSString *)MongodbId andNSDictionary:(NSDictionary *)obj{
    NSString *str = MongodbId;
    NSString *requestURL =[NSString stringWithFormat:@"%@%@",self.programaUrl,GETPIC];
    NSMutableDictionary *params =[NSMutableDictionary dictionary];
    if (str) {
        [params setObject:str forKey:@"str"];
    }else{
        [self LoginSystem:obj andBtn:_loginBtn];
        return;
    }
    
    
    
    [NetRequest requestUrl:requestURL andParamas:params andReturnBlock:^(NSData *data, NSError *error) {
        if(data&&!error){
            
            
            
            UIImage *image=[UIImage imageWithData:data];
            //            [self.imgArr addObject:image];
            ZMView *zmView = [[ZMView alloc]init];
            NSString *path;
            if (image) {
                if (userId()) {
                    path = [zmView saveImageToLocalimage:image filename:[NSString stringWithFormat:@"%@",userId()]];
                }else{
                    path = [zmView saveImageToLocalimage:image filename:@"头像1"];
                }
                
                //            _imagePath = path;
                
                saveUserIcon(path);
                NSMutableDictionary *paramss1;
                
                if(userIconMongodbId()){
                    paramss1 = [[NSMutableDictionary alloc]initWithDictionary: userIconMongodbId()];
                }else{
                    paramss1 = [[NSMutableDictionary alloc]init];
                    
                }
                if (userId()) {
                    NSString *strKey = [NSString stringWithFormat:@"%@",userId()];
                    
                    
                    if ([paramss1 valueForKey:strKey]) {
                        [paramss1 removeObjectForKey:strKey];
                    }
                    
                    
                    [paramss1 setObject:str forKey:strKey];
                }
                NSLog(@"%@",userId());
                
                
                saveUserIconMongodbId(paramss1);
                
                NSMutableDictionary *mutdic = userIconMongodbId();
                NSLog(@"%@",mutdic);
            }
            
            
            //            _headImg.image = image;
            
            
            
            
            
            
        }else{
            
        }
        
        [self LoginSystem:obj andBtn:_loginBtn];
    }];
    
}

+(NSTimer *)sharedNSTimer{
    @synchronized (self)
    {
        if (!_sharedNSTimer) {
            _sharedNSTimer = [[NSTimer alloc] init];
        }
    }
    return _sharedNSTimer;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    _myTimer = [LoginViewController sharedNSTimer];
    if ([_myTimer isValid]) {
        [_myTimer invalidate];
    }
    _myTimer = nil;
}


-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    if(focusTextField){
        [focusTextField resignFirstResponder];
    }
}

-(void)LoginSystem:(NSDictionary *)obj andBtn:(UIButton *)btn{
    NSNotificationCenter *noti = [NSNotificationCenter defaultCenter];
    saveLoginState(LOGSTATE);
    [noti postNotificationName:@"login" object:@"loginSuccees"];
    
    
    //*** save succeed the user name password for remember
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    saveUserName(userNameText.text);
    savePassWord(passWordText.text);
    saveLoginState(@"yes");
    [userDefault setObject:@"yes" forKey:@"isLogin"];
    if ([[obj objectForKey:@"loginInfo"] objectForKey:@"USERID"]) {
        [userDefault setObject:[[obj objectForKey:@"loginInfo"] objectForKey:@"USERID"] forKey:@"USERID"];//STUID 修改成USERID
    }
    
    //NSString *str =[obj objectForKey:@"loginInfo"];
    [userDefault synchronize];
    btn.enabled = YES;
    exchangeBtn.enabled = YES;
}

- (void)getProId{
    NSMutableDictionary *parama = [[NSMutableDictionary alloc]init];
    [parama setObject:@"0" forKey:@"source"];
    
    NSString *requestStr = [NSString stringWithFormat:@"%@%@", getBase(), PROJECTREQUEST_URL];
    [NetRequest requestUrl:requestStr andParamas:parama andReturnBlock:^(NSData *data, NSError *error) {
        if (!error&&data!=nil) {
            id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            NSString *string = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSLog(@"%@", string);
            //            NSString *str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            
            [self dataUes:obj];
            NSLog(@"%@", obj);
            
        }else{
            //[self showLabelWithText:@"网络中断，请检查网络"];
            NSString *str = [NSString stringWithFormat:@"%@", error.localizedDescription];
            [self showLabelWithText:str];
            
        }
    }];
    
}
-(void)dataUes:(id)obj{
    NSArray *arr = [[NSArray alloc]initWithArray:obj];
    
    if (!_projectArr) {
        _projectArr = [[NSMutableArray alloc] init];
    }
    
    [_projectArr removeAllObjects];
    
    
    
    NSString * str1 = getBase();
    NSArray *urlArr = [str1 componentsSeparatedByString:@":"];
    NSArray *usedArr = [[urlArr lastObject] componentsSeparatedByString:@"/"];
    NSString *usedStr = [usedArr firstObject];
    
    NSLog(@"%@",usedStr);
    
    
    for (NSDictionary *dic in arr) {
        ProjectModel *model = [[ProjectModel alloc]init];
        model = [model initWithDictionary:dic error:nil];
        if ([model.programa_url isEqualToString:@"localhost"]) {
            model.programa_url = @"192.168.6.150";
        }
        //这里添加了角色判断
        if ([getUserType() isEqualToString:UserISHPSTeacher]) {
            if([model.programa_name isEqualToString:@"主项目"]){
                //            model.pro_port = usedStr;
                [_projectArr addObject:model];
            }
        }else{
            if([model.programa_name isEqualToString:@"学员端"]){
                //            model.pro_port = usedStr;
                [_projectArr addObject:model];
            }
        }
        
        
    }
    
    
    
    
    ProjectModel *model = _projectArr[0];
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    [userDefault setObject:model.proId forKey:PROID];
    [userDefault setObject:model.programa_url forKey:PROGRAMA];
    [userDefault setObject:model.pro_port forKey:PORT];
    
    [userDefault synchronize];
    proID = model.proId;
    
    
    
    
}


#pragma mark - else
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
